library(ggplot2)
library(data.table)
library(scales)
library(RColorBrewer)

data_dir <- here::here('..','data')
load(file.path(data_dir, 'incucyte.Rdata'))
incucyte_dt[, day_f := factor(day_f, levels=sort(as.numeric(levels(day_f))))]

car_set <- c('41BB','CD28','BAFF-R','CD40','TACI')
chosen_measure <- 'redintensity'

Killing, CD4 and CD8 separately

#4 and 8 separate
ggplot(incucyte_dt[k562=='mkate_cd19' & !noise & t_type == 'cd4' & measurement == chosen_measure & car %in% car_set][, 
    car := factor(car, levels=car_set)], 
  aes(x=Elapsed, y=mean_value_norm, group=interaction(car, day_f,donor), fill=car)) + 
  geom_line(aes(color=car)) + 
  geom_ribbon(aes(ymin=mean_value_norm-std_error, ymax=mean_value_norm+std_error), alpha=0.3) +
  facet_grid(t_type+donor~day_f) + 
  ggtitle("Incucyte K562 Killing by mKate Total Integrated Intensity (normalized to starting)") +
  theme_minimal(base_size=20) + geom_vline(xintercept=0) + geom_hline(yintercept=0) +
  theme(plot.title = element_text(size = 25)) + 
  scale_x_continuous(expand=c(0,0), limits=c(0,150)) +
  scale_y_continuous('mKate Total Integrated Intensity\n(normalized to starting)',
    limits=c(1e-2,1e1), trans=log10_trans()) +
  theme(plot.title = element_text(hjust = 0.5)) + 
  scale_color_brewer(palette='Set1') + 
  scale_fill_brewer(palette='Set1') + 
  theme(panel.spacing = unit(2, "lines"))
## Warning: Transformation introduced infinite values in continuous y-axis

## Warning: Transformation introduced infinite values in continuous y-axis

## Warning: Transformation introduced infinite values in continuous y-axis

## Warning: Transformation introduced infinite values in continuous y-axis

## Warning: Transformation introduced infinite values in continuous y-axis
## Warning: Removed 7716 rows containing missing values (geom_path).

ggplot(incucyte_dt[k562=='mkate_cd19' & !noise & t_type == 'cd8' & measurement == chosen_measure & car %in% car_set][, 
    car := factor(car, levels=car_set)], 
  aes(x=Elapsed, y=mean_value_norm, group=interaction(car, day_f,donor), fill=car)) + 
  geom_line(aes(color=car)) + 
  geom_ribbon(aes(ymin=mean_value_norm-std_error, ymax=mean_value_norm+std_error), alpha=0.3) +
  facet_grid(t_type+donor~day_f) + 
  ggtitle("Incucyte K562 Killing by mKate Total Integrated Intensity (normalized to starting)") +
  theme_minimal(base_size=20) + geom_vline(xintercept=0) + geom_hline(yintercept=0) +
  theme(plot.title = element_text(size = 25)) + 
  scale_x_continuous(expand=c(0,0), limits=c(0,70)) +
  scale_y_continuous('mKate Total Integrated Intensity\n(normalized to starting)',
    limits=c(1e-2,1e1), trans=log10_trans()) +
  theme(plot.title = element_text(hjust = 0.5)) + 
  scale_color_brewer(palette='Set1') + 
  scale_fill_brewer(palette='Set1') + 
  theme(panel.spacing = unit(2, "lines"))
## Warning: Transformation introduced infinite values in continuous y-axis
## Warning: Removed 414 rows containing missing values (geom_path).

Killing, normalized to no-car controls

ggplot(incucyte_dt[k562=='mkate_cd19' & !noise & t_type == 'cd4' & measurement == chosen_measure], 
  aes(x=Elapsed, y=mean_value_none, group=interaction(car, day_f,donor), fill=car)) + 
  geom_line(aes(color=car)) + 
  facet_grid(t_type+donor~day_f) + 
  ggtitle("Incucyte K562 Killing by mKate Total Integrated Intensity (normalized to starting)") +
  theme_minimal(base_size=20) + geom_vline(xintercept=0) + geom_hline(yintercept=0) +
  theme(plot.title = element_text(size = 25)) + 
  scale_x_continuous(expand=c(0,0), limits=c(0,150)) +
  scale_y_continuous('mKate Total Integrated Intensity\n(normalized to growth without CAR)',
    limits=c(1e-2,1e1), trans=log10_trans()) +
  theme(plot.title = element_text(hjust = 0.5)) + 
  scale_color_brewer(palette='Set1') + 
  scale_fill_brewer(palette='Set1') + 
  theme(panel.spacing = unit(2, "lines"))
## Warning: Transformation introduced infinite values in continuous y-axis

## Warning: Transformation introduced infinite values in continuous y-axis
## Warning: Removed 13509 rows containing missing values (geom_path).

ggplot(incucyte_dt[k562=='mkate_cd19' & !noise & t_type == 'cd8' & measurement == chosen_measure], 
  aes(x=Elapsed, y=mean_value_none, group=interaction(car, day_f,donor), fill=car)) + 
  geom_line(aes(color=car)) + 
  facet_grid(t_type+donor~day_f) + 
  ggtitle("Incucyte K562 Killing by mKate Total Integrated Intensity (normalized to starting)") +
  theme_minimal(base_size=20) + geom_vline(xintercept=0) + geom_hline(yintercept=0) +
  theme(plot.title = element_text(size = 25)) + 
  scale_x_continuous(expand=c(0,0), limits=c(0,70)) +
  scale_y_continuous('mKate Total Integrated Intensity\n(normalized to growth without CAR)',
    limits=c(1e-2,1e1), trans=log10_trans()) +
  theme(plot.title = element_text(hjust = 0.5)) + 
  scale_color_brewer(palette='Set1') + 
  scale_fill_brewer(palette='Set1') + 
  theme(panel.spacing = unit(2, "lines"))
## Warning: Transformation introduced infinite values in continuous y-axis
## Warning: Removed 2698 rows containing missing values (geom_path).